Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2GameUser = require("GameUser");
var $2EventCenter = require("EventCenter");
var $2EventDefine = require("EventDefine");
var $2PhoneManager = require("PhoneManager");
var $2Globe = require("Globe");
var $2ServerConfig = require("ServerConfig");
var c = ["只能分享到群哦", "分享失败，再试试", "请分享到不同的群", "网络卡住了，请重新分享一次", "分享失败，看视频也可以哦"];
var def_ShareMgr = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.onListen = false;
    this.shareTimes = 0;
    this.shareFailReason = "网络卡住了，请重新分享一次";
    this.shareTime_min = 1;
    this.shareTime_max = 8;
    this.shareIndex = 0;
    this.shareSuccTimes = 0;
  }
  return babel_createClass(_ctor, [{
    key: "share",
    value: function share(e, t) {
      this.shareCallBack = null;
      var n = Math.floor(100 * Math.random()) % 2 == 0 ? "https://mmocgame.qpic.cn/wechatgame/A1QMmbkSORpKcNY12hfRfibAT4WrY2DuPABKlu3LOqvpJ8zmlSiaWTZicbCQ7DDFZSq/0" : "https://mmocgame.qpic.cn/wechatgame/XXMicGuvic8EYekxic2MZj6WqmQ9sk4VQCqGhMRyGXCWolWx2WKpBSLJyIMW4Y8Ga1Y/0";
      var o = ["你厉害你来把第二关过了，最难密室消除！", "全球通关率仅0.01%的密室消除游戏", "在线即玩，快来体验！", "赠送【体力*1】点击领取"][Math.floor(40 * Math.random()) % 4];
      if (t) {
        undefined !== t.image && (n = t.image);
        undefined !== t.title && (o = t.title);
      }
      window.wx.shareAppMessage({
        title: o,
        imageUrl: n,
        success() {
          console.log("分享成功");
          e && e(true);
        },
        fail() {
          console.log("分享失败");
          e && e(false);
        },
        complete() {
          console.log("分享结束");
        }
      });
    }
  }, {
    key: "shareAppMessage",
    value: function shareAppMessage(e, t) {
      var _this82 = this;
      t = t || {};
      this.shareCallBack = e;
      this.onListen = true;
      this.shareIndex = 0;
      null == this.arrShareInfo && (this.arrShareInfo = []);
      var n = this.arrShareInfo[this.shareIndex];
      console.log("shareAppMessage");
      var i = Math.floor(100 * Math.random()) % 2 == 0 ? "https://mmocgame.qpic.cn/wechatgame/A1QMmbkSORpKcNY12hfRfibAT4WrY2DuPABKlu3LOqvpJ8zmlSiaWTZicbCQ7DDFZSq/0" : "https://mmocgame.qpic.cn/wechatgame/XXMicGuvic8EYekxic2MZj6WqmQ9sk4VQCqGhMRyGXCWolWx2WKpBSLJyIMW4Y8Ga1Y/0";
      n = {
        title: ["你厉害你来把第二关过了，最难密室消除！", "全球通关率仅0.01%的密室消除游戏", "在线即玩，快来体验！", "赠送【体力*1】点击领取"][Math.floor(40 * Math.random()) % 4],
        imageUrl: i
      };
      var s = "imgId=" + (this.shareIndex + 1);
      if (t) {
        for (var _o95 in t) {
          s += "&" + _o95 + "=" + t[_o95];
        }
      }
      s += "&isinvitekey=" + $2GameUser.default.getInstance().openid;
      s += "&launch=" + $2PhoneManager.default.getInstance().launch;
      console.log("分享参数 query", s);
      wx.shareAppMessage({
        title: t.title || n.title || "",
        imageUrl: n.imageUrl || "",
        query: s,
        success() {
          console.log("分享成功");
        },
        fail() {
          console.log("分享失败");
          _this82.shareCallBack && _this82.shareCallBack(false);
        },
        complete() {
          console.log("分享结束");
        }
      });
      this.shareIndex++;
      this.shareIndex >= this.arrShareInfo.length && (this.shareIndex = 0);
    }
  }, {
    key: "PreInit",
    value: function PreInit(e) {
      console.log("PreInit----------");
      this.shareIndex = 0;
      this.arrShareInfo = e;
      if (window.wx) {
        console.log("PreInit*-**************");
        $2EventCenter.default.regisEvent($2EventDefine.default.EVENT_ONHIDE, this.wxOnHide, this);
        $2EventCenter.default.regisEvent($2EventDefine.default.EVENT_ONSHOW, this.wxOnShow, this);
      }
    }
  }, {
    key: "ShareTimeLimit",
    set(e) {
      this.shareTime_min = e;
      console.log("ShareTimeLimit", this.shareTime_min);
    }
  }, {
    key: "wxOnShow",
    value: function wxOnShow(e) {
      console.log("::wx on show", this.onListen);
      this.replayBgm && this.replayBgm();
      if (this.onListen) {
        this.onListen = false;
        this.shareEndTime = new Date().getTime();
        var _e40 = (this.shareEndTime - this.shareStartTime) / 1e3;
        this.shareFailReason = c[this.shareTimes];
        console.log("shareTime:" + _e40);
        this.shareTimes = 1;
        console.log("shareTimes:" + this.shareTimes);
        console.log(this.shareTime_min, "-------", this.shareTime_max);
        switch (this.shareTimes) {
          case 1:
          case 2:
          case 3:
          case 4:
          case 5:
            if (_e40 > this.shareTime_min && _e40 < this.shareTime_max) {
              this.shareSuccessCallBack();
            } else {
              this.shareFailCallBack();
            }
        }
      }
    }
  }, {
    key: "shareSuccessCallBack",
    value: function shareSuccessCallBack() {
      this.shareSuccTimes += 1;
      this.shareCallBack && this.shareCallBack(true);
    }
  }, {
    key: "shareFailCallBack",
    value: function shareFailCallBack() {
      this.shareCallBack && this.shareCallBack(false);
    }
  }, {
    key: "wxOnHide",
    value: function wxOnHide() {
      console.log("::wx on hide");
      if (this.onListen) {
        this.shareStartTime = new Date().getTime();
        this.shareTimes += 1;
      }
    }
  }, {
    key: "setShare",
    value: function setShare(e, t, n) {
      var o = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3.5;
      var i = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 8;
      this.shareCallBack = e;
      this.confirmFunc = t;
      this.cancleFun = n;
      this.onListen = true;
      this.shareTime_min = o;
      this.shareTime_max = i;
      this.DoShare();
    }
  }, {
    key: "Reset",
    value: function Reset() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
    }
  }, {
    key: "shareFailModel",
    value: function shareFailModel() {
      var _this83 = this;
      wx.showModal({
        title: "提示",
        content: this.shareFailReason,
        confirmText: this.shareTimes < 4 ? "重新分享" : "我要观看",
        success(e) {
          if (e.confirm) {
            console.log("用户点击确定");
            if (_this83.shareTimes < 3) {
              _this83.DoShare();
            } else {
              _this83.confirmFunc && _this83.confirmFunc();
            }
          } else if (e.cancel) {
            console.log("用户点击取消", _this83.cancleFun), _this83.cancleFun && _this83.cancleFun();
          }
        }
      });
    }
  }, {
    key: "DoShare",
    value: function DoShare() {
      if (window.wx) {
        null == this.arrShareInfo && (this.arrShareInfo = []);
        var _e41 = this.arrShareInfo[this.shareIndex];
        null == _e41 && (_e41 = {
          title: "",
          imageUrl: ""
        });
        console.log("DoShare shareInfo：", _e41);
        wx.shareAppMessage({
          title: _e41.title || "",
          imageUrl: _e41.imageUrl || "",
          query: "imgId=" + (this.shareIndex + 1) + "&isinvitekey=" + $2GameUser.default.getInstance().openid + "&launch=" + $2PhoneManager.default.getInstance().launch,
          success() {
            console.log("分享成功");
          },
          fail() {
            console.log("分享失败");
          },
          complete() {
            console.log("分享结束");
          }
        });
        this.shareIndex++;
        this.shareIndex >= this.arrShareInfo.length && (this.shareIndex = 0);
      }
    }
  }, {
    key: "OnShareApp",
    value: function OnShareApp() {}
  }, {
    key: "onShareAppMessage",
    value: function onShareAppMessage() {
      if (null == window.wx) {
        return;
      }
      var e = "https://mmocgame.qpic.cn/wechatgame/A1QMmbkSORpKcNY12hfRfibAT4WrY2DuPABKlu3LOqvpJ8zmlSiaWTZicbCQ7DDFZSq/0";
      var t = "这关你不行...";
      var n = $2ServerConfig.default.getInstance().gameconfig.config.share;
      if (n.length > 0) {
        var _o96 = $2Globe.default.getInstance().random(0, n.length - 1);
        t = n[_o96].title;
        e = n[_o96].imageUrl;
      }
      console.log("image:", e, "--------title:", t);
      window.wx.onShareAppMessage(function () {
        return {
          title: t,
          imageUrl: e
        };
      });
    }
  }], [{
    key: "Instance",
    get() {
      _ctor._instance || (_ctor._instance = new _ctor());
      return _ctor._instance;
    }
  }]);
}();
exports.default = def_ShareMgr;